package com.hsy.application.mvp.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.widget.RadioGroup;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.hsy.application.R;
import com.hsy.application.di.component.DaggerMainComponent;
import com.hsy.application.mvp.contract.MainContract;
import com.hsy.application.mvp.presenter.MainPresenter;
import com.hsy.application.mvp.ui.adapter.MainAdapter;
import com.hsy.commonsdk.app.AppConstant;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;

import static com.jess.arms.utils.Preconditions.checkNotNull;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 02/17/2019 16:43
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
public class MainActivity extends BaseActivity<MainPresenter> implements MainContract.View, ViewPager.OnPageChangeListener, RadioGroup.OnCheckedChangeListener {

    @BindView(R.id.main_viewpager)
    ViewPager mainViewpager;
    @BindView(R.id.main_buttom)
    RadioGroup mainButtom;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerMainComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .view(this)
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_main; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        mPresenter.init();
        mainButtom.setOnCheckedChangeListener(this);
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    public FragmentManager getManager() {
        return getSupportFragmentManager();
    }

    @Override
    public void setAdapter(MainAdapter mainAdapter) {
        mainViewpager.setAdapter(mainAdapter);
        mainViewpager.setOnPageChangeListener(this);
    }


    @Override
    public void onPageScrolled(int i, float v, int i1) {

    }

    @Override
    public void onPageSelected(int i) {
        mainButtom.getChildAt(i).performClick();
    }

    @Override
    public void onPageScrollStateChanged(int i) {

    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId) {
            case R.id.main_buttom_business:
                mainViewpager.setCurrentItem(0);
                break;
            case R.id.main_buttom_communication:
                if (!AppConstant.getInstance().isLogin()){
                    showLoginDialog();
                   return;
                }
                mainViewpager.setCurrentItem(1);
                break;
            case R.id.main_buttom_opeartion:
                if (!AppConstant.getInstance().isLogin()){
                    showLoginDialog();
                    return;
                }
                mainViewpager.setCurrentItem(2);
                break;
            case R.id.main_buttom_setting:
                mainViewpager.setCurrentItem(3);
                break;
        }
    }

    private void showLoginDialog() {

    }
}
